<!DOCTYPE HTML PUBLIC "-//w3c//dtd xhtml 1.1//en" "http://www.w3.org/tr/xhtml11/dtd/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-PT">
	<head>
		<title>DOMForms</title>
		<script type="text/javascript" src="../../working/core.js"></script>
		<script type="text/javascript">
			
			if(!window.console){
				window.console={
					log:function(){
						alert(Array.prototype.join.call(arguments," , "));
					},
					inspect:function(){
						for(p in o){
							alert(p + " : " + o[p])
						}
					}
				}
			}
			
			
			var Form={
					activeElement:false,
					create:function(o){
						
						if(!o){
							return arguments.callee.map($T("form"),this);
						}
						
						var f = this;
						
						$(o).event("click",function(e){
							e.target.form.activeElement = e.target;
						})
						
						$(o).event("submit",function(e){
							f.serialize(this,e)
							e.preventDefault();
							return false;
						})
						
						/*
						o.submit=this.submit;
						o.reset=this.reset;
						o.elements = $T("input","textarea","select","button");
						o.onkeypress=function(e){
							if(e.keyCode==13){
								var f;
								if(f=this.getAttribute("onsubmit")){
									f=new Function("event",f);
									if(!f.call(this)){
										e.preventDefault();
										return false;
									}else{
										this.submit();
									}
								}
							}
						}*/
						
					},
					/*submit:function(form, e){
						this.__form__ = document.createElement("form");
						this.__form__.acceptCharset = this.acceptCharset;
						this.__form__.action = this.action;
						this.__form__.enctype = this.enctype;
						this.__form__.encoding = this.encoding;
						this.__form__.method = this.method;
						this.__form__.target = this.target;
						
					},*/
					reset:function(){},
					serialize:function(form,e){
						var str=[];

						for( var i=0, o, l=form.elements.length; i<l; i++){	
							o = form.elements[i]
							if(!o.disabled){
								switch(o.nodeName.toLowerCase()){
									case "input":
										switch(o.type.toLowerCase()){
											case "radio":
											case "checkbox":
												if(o.checked){
													str.push(o.name + "=" + o.value);
												}
												break;
											case "button":
											case "submit":
												continue; break;
											default:
												str.push(o.name + "=" + o.value);
										};
										break;
									case "select":
										if(o.multiple){
											for(var z=0;z<o.options.length;z++){
												if(o.options[z].selected){
													str.push(o.name + "=" + o.options[z].value);
												}
											}
										}else{
											str.push(o.name + "=" + o.value);
										};
										break;
									case "button": 
										continue; break;
									default:
										str.push(o.name + "=" + o.value);
										break;
								}
							}
						};
						
						submit = form.activeElement || e.explicitOriginalTarget || e.relatedTarget || document.activeElement || false;
						if(submit){
							str.push(submit.name + "=" + submit.value);
						}
						
						alert(str.join("\n"))
						
						e.preventDefault();
						return false;
					}
				}
		
			compono.ready(function(){
				Form.create();
			})
		</script>
	</head>
	<body>
		<form action="domform.html" method="post" id="fsexo">
			<input type="text" name="nome" />
			<input type="text" name="lastName" disabled="disabled" value="last-name" />
			<input type="password" name="senha" />
			<input type="hidden" name="storage" />
			<input type="file" name="foto" />
			<textarea name="desc"></textarea>
			<div>
				<label>Masculino <input type="radio" name="sexo" value="m" /></label>
				<label>Feminino <input type="radio" name="sexo" value="f" /></label>
				<label>Feminino <input type="radio" name="sexo" value="t" /></label>
				<input type="submit" name="OK1" value="ok1" />
			</div>
			<select name="fSelect">
				<option value="a">a</option>
				<option value="b">b</option>
				<option value="c">c</option>
			</select>
			<input type="submit" value="ok2" />
			<select name="fMSelect" multiple="multiple">
				<option value="ma">ma</option>
				<option value="mb">mb</option>
				<option value="mc">mc</option>
			</select>
			<label>Designer <input type="checkbox" name="pro" value="d" /></label>
			<label>Programmer <input type="checkbox" name="pro" value="p" /></label>
			<label>IA <input type="checkbox" name="pro" value="ia" /></label>
			<input type="button" name="OKButton" value="OKButton" />
			<button type="submit" name="submitButton" value="s1">submitButton</button>
			<button type="button" name="buttonButton" value="s2">buttonButton</button>
		</form>
	</body>
</html>